package com.kaoshi.myweb.webtest.quartz;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.PersistJobDataAfterExecution;

public class BadJob1 implements Job {

	@Override
	public void execute(JobExecutionContext context)
			throws JobExecutionException {
		// 任务执行的时间
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String jobName = context.getJobDetail().getKey().getName();
		System.out.println("---" + jobName + " 在[ " + dateFormat.format(new Date())+ " ] 执行!!  ") ;
		System.err.println("--- 在 BadJob  2   中发生 错误, 将停止运行!! ");
		JobExecutionException e2 = new JobExecutionException(new Exception());
		// 设置了 job 类抛出异常后的处理方式 ,此处意为 发生异常后 立即重新执行
		e2.setRefireImmediately(true);
		
		// 抛出异常
		throw e2;
	}
}
